package com.xx.phonecall;

import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.stkcall.library.PhoneInfo;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>------------------------------------------------------
 * <p>Copyright (C) wasu company, All rights reserved.
 * <p>------------------------------------------------------
 *
 * @author: xujie
 * @date: 9/20/22
 */
public class AudioAdapter extends RecyclerView.Adapter<AudioAdapter.ViewHolder> {

    List<File> list;

    public AudioAdapter() {
        list = new ArrayList<>();
    }

    public void setList(List<File> list){
        if(list != null){
            this.list = list;
        }
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(android.R.layout.simple_list_item_1, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        File file = list.get(position);
        if(!TextUtils.isEmpty(file.getName())) {
            holder.text.setText(file.getName());
        }else {
            holder.text.setText(file.getPath());
        }
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder{
        TextView text;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            text = itemView.findViewById(android.R.id.text1);
        }
    }
}
